package cn.yj.frame.netty;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.net.InetSocketAddress;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author 永健
 * @since 2022-01-17 16:58
 */
public abstract class AbstractNettyServer implements INettyServer {

    private static final Logger log= LoggerFactory.getLogger(NettyServer.class);



    @Override
    public void start(InetSocketAddress inetSocketAddress) {
        final ExecutorService executorService = Executors.newFixedThreadPool(1);
        log.info("netty服务启动监听端口={}",inetSocketAddress.getPort());
        // 使用线程池异步启动，不然程序会阻塞
        executorService.execute(()->run(inetSocketAddress));
        executorService.shutdown();
    }


    abstract void run(InetSocketAddress inetSocketAddress);
}
